// 获取当前设备方向
export function getOrientation() {
  return new Promise((resolve, reject) => {
    uni.getSystemInfo({
      success(res) {
        const { screenWidth, screenHeight } = res
        resolve(screenWidth > screenHeight ? 'landscape' : 'portrait')
      },
      fail(err) {
        reject(err)
      },
    })
  })
}

// 图片旋转
export function rotateImage(tempFilePath) {
  return new Promise((resolve, reject) => {
    uni.getImageInfo({
      src: tempFilePath,
      success(res) {
        const { orientation } = res
        let rotate = 0
        if (orientation === 'up') {
          rotate = 0
        } else if (orientation === 'down') {
          rotate = 180
        } else if (orientation === 'left') {
          rotate = -90
        } else if (orientation === 'right') {
          rotate = 90
        }
        uni.compressImage({
          src: tempFilePath,
          rotate,
          success(compressRes) {
            resolve(compressRes.tempFilePath)
          },
          fail(err) {
            reject(err)
          },
        })
      },
      fail(err) {
        reject(err)
      },
    })
  })
}